package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.MyScoreList;
import com.myapp.ruyixing.model.MyScoreList.Score;

public class MyScoreListParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {
		MyScoreList list = new MyScoreList();

		ListModelParser.parseListModel(list, jsonObject);
		JSONObject data = jsonObject.optJSONObject("data");
		JSONArray array = data.optJSONArray("items");
		list.myscore = data.optInt("myscore", 0);
		list.items = new ArrayList<Score>();
		for (int i = 0; array != null && i < array.length(); i++) {
			JSONObject object = array.optJSONObject(i);
			if (object != null) {
				Score item = new Score();
				item.datetime = object.optString("datetime", "");
				item.score = object.optString("score", "");
				item.event = object.optString("event", "");
				list.items.add(item);
			}
		}

		return list;

	}
}
